package com.fenghongzhang.day005rxprem;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

public class MyMatrix extends View {
    Matrix matrix ;
    Paint paint;
    Bitmap bitmap;
    public MyMatrix(Context context) {
        super(context);
        init();
    }

    public MyMatrix(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        matrix = new Matrix();

        paint = new Paint();
        bitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(bitmap,matrix,paint);
    }

    public void scale(int x ,int y){
//        matrix.setScale(x,y);
        matrix.postScale(x,y);
//        matrix.preScale(x,y);
        invalidate();

    }

    public void setTranslate(int x ,int y){
//        matrix.setTranslate(x,y);
        matrix.postTranslate(x,y);
//        matrix.preTranslate(x,y);
        invalidate();
    }

    public void setSkew(float x,float y){
        matrix.setSkew(x,y);
        invalidate();

    }

    public void mark(){
        Bitmap b = Bitmap.createBitmap(this.bitmap.getWidth(), this.bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(b);
        canvas.drawBitmap(bitmap,0,0,paint);
        canvas.drawText("shuai",0,10,paint);
        this.bitmap = b;
        invalidate();
    }


}
